#include <iostream>
#include <queue>
using namespace std;
#define maxn 5005
const int mode = 80112002;
int n, m, u, v, ans;
int vertMat[maxn][maxn], roads[maxn];
int inDegree[maxn], outDegree[maxn];
queue<int> que;
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        cin >> u >> v; //u->v
        vertMat[u][v] = 1;
        inDegree[v]++;
        outDegree[u]++;
    }
    for (int i = 1; i <= n; ++i)
    {
        if (inDegree[i] == 0)
            roads[i]++, que.push(i); //生产者入队
    }
    while (!que.empty())
    {
        int now = que.front();
        que.pop();
        for (int j = 1; j <= n; ++j)
        {
            if (vertMat[now][j] == 1)
            {
                roads[j] += roads[now];
                roads[j] %= mode;
                inDegree[j]--;
                if (inDegree[j] == 0)
                {
                    if (outDegree[j] == 0)
                    {
                        ans += roads[j];
                        ans %= mode;
                    }
                    que.push(j);
                }
            }
        }
    }
    cout << ans;
    return 0;
}